<template>
  <div class="filePassword" v-if="$store.state.showFilePassword">
    <!-- 头部 -->
    <div class="filePasswordHeader">
      <span>文档密码</span>
      <!-- 关闭按钮 -->
      <i class="iconfont icon-guanbi" @click="hideFilePassword"></i>
    </div>
    <!-- 文档密码 -->
    <div class="filePasswordMain">
      <input
        type="password"
        placeholder="请输入文档密码"
        v-model="filePassword"
        @keydown.enter="passwordConfirm"
        class="filePasswordInput"
      />
    </div>
    <!-- 确定按钮 -->
    <button class="filePasswordBtn" @click="passwordConfirm">确定</button>
  </div>
</template>

<script>
export default {
  name: "FilePassword",
  data() {
    return {
      filePassword: "",
    };
  },
  methods: {
    // 隐藏设置名称
    hideFilePassword() {
      // this.showfilePassword = false;
      this.$store.commit("setShowFilePassword", false);
      this.filePassword = "";
      document.querySelector(".filePasswordInput").style.border = "";
    },
    // 点击设置名字确定按钮时调用
    passwordConfirm() {
      // 向后端发送请求验证密码是否正确
      console.log("向后端发送请求验证密码是否正确");
      let password = "123456";
      // 密码正确
      if (password === this.filePassword) {
        this.$bus.$emit("getFilePassword", "1");
        document.querySelector(".filePasswordInput").style.border = "";
        this.$store.commit("setShowFilePassword", false);
        this.filePassword = "";
      } else {
        document.querySelector(".filePasswordInput").style.border =
          "1px solid rgb(221, 79, 67)";
      }
    },
  },
};
</script>

<style lang="less" scoped>
.filePassword {
  width: 380px;
  // height: 300px;
  background-color: rgb(234, 246, 255);
  // background-color: white;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 10px;
  // border: rgb(47, 47, 47) 1px solid;
  // z-index: 101;
  .filePasswordHeader {
    border-radius: 10px 10px 0 0;
    width: 100%;
    height: 30px;
    background-color: rgb(106, 168, 212);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    color: white;
    i {
      position: absolute;
      right: 10px;
      font-size: 14px;
      cursor: pointer;
    }
  }
  .filePasswordMain {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 20px 0;
    input {
      // border: none;
      outline: none;
      // background-color: rgb(106, 168, 212);
      border: 1px solid rgb(106, 168, 212) s;
      border-radius: 5px;
      width: 60%;
      height: 30px;
      padding: 0 20px;
      border: 1px solid transparent;
      // 鼠标移入输入框包裹器时
      &:hover {
        // 边框
        border: 1px solid #0182c7;
      }
    }
  }
  .filePasswordBtn {
    display: block;
    width: 90px;
    height: 30px;
    background-color: rgb(106, 168, 212);
    margin: 0 auto;
    border-radius: 999px;
    text-align: center;
    line-height: 30px;
    color: white;
    margin-bottom: 20px;
    cursor: pointer;
    &:hover {
      background-color: rgba(106, 168, 212, 0.8);
    }
  }
}
@media (max-width: 380px) {
  .filePassword {
    width: 100%;
  }
}
</style>